from selenium import webdriver
# 导入动作链对应的类
from selenium.webdriver import ActionChains
from time import sleep

if __name__ == "__main__":
    bro = webdriver.Chrome(executable_path='./chromedriver')
    # 隐性等待，最长等20秒
    bro.implicitly_wait(20)
    # 发起HTTP请求
    bro.get('https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
    # 如果定位的标签存在于iframe标签里，则必须切换浏览器标签定位的作用域
    bro.switch_to.frame('iframeResult')
    source = bro.find_element_by_css_selector('#draggable')
    target = bro.find_element_by_css_selector('#droppable')

    # 实例化一个动作链对象
    action = ActionChains(bro)
    # 点击长按指定的标签
    action.click_and_hold(source)

    for i in range(5):
        # perform()立即执行动作链的操作
        # move_by_offset(x,y):x水平方向，y垂直方向
        action.move_by_offset(xoffset=17, yoffset=0).perform()
        sleep(0.5)

    # 释放动作链
    action.release()
    sleep(0.5)
    # 关闭浏览器
    bro.quit()
